//
//  Zhanghaoanquan_vc.m
//  ainkjj
//
//  Created by MAX on 2020/4/17.
//  Copyright © 2020 zhiyiLiu. All rights reserved.
//

#import "Zhanghaoanquan_vc.h"
#import "XBConst.h"
#import "XBSettingCell.h"
#import "XBSettingItemModel.h"
#import "XBSettingSectionModel.h"
#import "Masonry.h"

#import <Photos/Photos.h>
#import <ZLPhotoBrowser/ZLPhotoBrowser.h>

#import "MMAlertView.h"
#import "Modify_phoneNum_vc.h"
#import "PPNetworkHelper.h"


@interface Zhanghaoanquan_vc ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *sectionArray;


@property (nonatomic, strong) NSMutableArray<UIImage *> *lastSelectPhotos;
@property (nonatomic, strong) NSMutableArray<PHAsset *> *lastSelectAssets;

@property (nonatomic, strong) NSArray *arrDataSources;

@property (nonatomic, assign) BOOL isOriginal;
@end

@implementation Zhanghaoanquan_vc

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupSections];
    [self setupUI];
}
- (void)avatarAction{
    
    
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *imagePickerAction = [UIAlertAction actionWithTitle:@"从手机相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self btnSelectPhotoLibrary];
        
        
    }];
    [imagePickerAction setValue:rgb(51,51,51) forKey:@"_titleTextColor"];
    [alertVc addAction:imagePickerAction];



    NSString *takePhotoTitle = @"拍照";
    UIAlertAction *takePhotoAction = [UIAlertAction actionWithTitle:takePhotoTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self showCamera];
    }];
    [takePhotoAction setValue:rgb(51,51,51) forKey:@"_titleTextColor"];

    [alertVc addAction:takePhotoAction];
    
    UIAlertAction *chakan_img_action = [UIAlertAction actionWithTitle:@"查看大图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        [AuthSignin_model sharedInstance].data.user_info.avatar_url = @"https://pic1.zhimg.com/v2-c723a5ca6e36326c6396aaa193699578_xs.jpg";
        if ([AuthSignin_model sharedInstance].data.user_info.avatar_url.length == 0) {
            [MBProgressHUD showInfoMessage:@"无可预览的头像"];
            return;
        }
        NSArray *arrNetImages = @[GetDictForPreviewPhoto([NSURL URLWithString:AuthSignin_model.sharedInstance.data.user_info.avatar_url], ZLPreviewPhotoTypeURLImage)];
        
        // 预览网络图片
        [[self getPas] previewPhotos:arrNetImages index:0 hideToolBar:YES complete:^(NSArray * _Nonnull photos) {
            // your codes
        }];

    }];
    [chakan_img_action setValue:rgb(51,51,51) forKey:@"_titleTextColor"];

    [alertVc addAction:chakan_img_action];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [cancelAction setValue:rgb(51,51,51) forKey:@"_titleTextColor"];

    [alertVc addAction:cancelAction];
    [self presentViewController:alertVc animated:YES completion:nil];
}



#pragma mark - UI
- (void)setupUI{
    self.title = @"账号安全";
    
    
    UITableView *tableView = [UITableView new];
    self.tableView = tableView;
    [self.view addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make){
        make.bottom.mas_equalTo(self.view).offset(0);
        make.left.right.mas_equalTo(self.view);
        
        make.top.mas_equalTo(self.view).offset(0);
    }];
    
    tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    tableView.sectionHeaderHeight = .01;
    tableView.sectionFooterHeight = .01;
    tableView.dataSource = self;
    tableView.delegate = self;
    
}

- (void)setupSections{
    
    
    //更新磁盘
    //    [XLNewsModelKeyCacheTool saveUserModel:user];
    
    //************************************section1
    XBSettingItemModel *item1 = [[XBSettingItemModel alloc]init];
    item1.funcName = @"头像";
    
    item1.iconImageUrl = [AuthSignin_model sharedInstance].data.user_info.avatar_url;
    item1.iconPlaceHolderImgName = @"mine_head_icon";
    item1.itemRowHeight = 90.f;
    item1.accessoryType = XBSettingAccessoryTypeIconView;
    
    XBSettingItemModel *item2 = [[XBSettingItemModel alloc]init];
    item2.funcName = @"请设置名称";
    item2.detailText = [AuthSignin_model sharedInstance].data.user_info.nick_name;
    item2.accessoryType = XBSettingAccessoryTypeDisclosureIndicator;
    item2.itemRowHeight = 60.f;
    
    
    
    XBSettingItemModel *item3 = [[XBSettingItemModel alloc]init];
    item3.funcName = @"绑定手机";
    item3.detailText = [AuthSignin_model sharedInstance].data.user_info.mobile;
    item3.accessoryType = XBSettingAccessoryTypeDisclosureIndicator;
    item3.itemRowHeight = 60.f;
    
    
    //    item3.accessoryType = XBSettingAccessoryTypeSwitch;
    //    item3.switchValueChanged = ^(BOOL isOn) {
    //        DLog(@"%@", @(isOn));
    //    };
    //
    XBSettingSectionModel *section1 = [[XBSettingSectionModel alloc]init];
    XBSettingSectionModel *section2 = [[XBSettingSectionModel alloc]init];
    
    section1.itemArray = @[item1];
    section2.itemArray = @[ item2, item3];
    
    self.sectionArray = @[section1, section2].mutableCopy;
    
    [self.tableView reloadData];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return self.sectionArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    XBSettingSectionModel *sectionModel = self.sectionArray[section];
    return sectionModel.itemArray.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"setting";
    XBSettingSectionModel *sectionModel = self.sectionArray[indexPath.section];
    XBSettingItemModel *itemModel = sectionModel.itemArray[indexPath.row];
    
    XBSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[XBSettingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    cell.backgroundColor=[UIColor whiteColor];
    
    cell.item = itemModel;
    //    cell.funcNameLabel.textColor = XLNormalTextColor;
    //    cell.layer.cornerRadius=8;
    //    cell.clipsToBounds=YES;
    //    UIImageView *lineView=[[UIImageView alloc]init];
    //    lineView.image=[UIImage imageNamed:@"mineBackImageV"];
    //    cell.backgroundView=lineView;
    cell.indicator.image=[UIImage imageNamed:@"mine_next_icon"];
    return cell;
}

#pragma mark - Table view delegate
//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
//{
//    XBSettingSectionModel *sectionModel = self.sectionArray[section];
//    return sectionModel.sectionHeaderHeight;
//}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    XBSettingSectionModel *sectionModel = self.sectionArray[indexPath.section];
    XBSettingItemModel *itemModel = sectionModel.itemArray[indexPath.row];
    
    return itemModel.itemRowHeight;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    XBSettingSectionModel *sectionModel = self.sectionArray[indexPath.section];
    XBSettingItemModel *itemModel = sectionModel.itemArray[indexPath.row];
    NSLog(@"点击：%@",itemModel.funcName);
 
    if ([itemModel.funcName isEqualToString:@"头像"]) {
        
        [self avatarAction];
        
    }else if ([itemModel.funcName isEqualToString:@"请设置名称"]) {
        [self modify_name];
    }else if ([itemModel.funcName isEqualToString:@"绑定手机"]) {
        
        Modify_phoneNum_vc *vc= [[Modify_phoneNum_vc alloc]init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
}
#pragma mark - ================== 修改姓名 ==================

- (void)modify_name{
    
    QMUIDialogTextFieldViewController *dialogViewController = [[QMUIDialogTextFieldViewController alloc] init];
    dialogViewController.title = @"请输入名称";
    [dialogViewController addTextFieldWithTitle:nil configurationHandler:^(QMUILabel *titleLabel, QMUITextField *textField, CALayer *separatorLayer) {
        textField.placeholder = @"请输入新名称";
        textField.text = [AuthSignin_model sharedInstance].data.user_info.nick_name;
        //        textField.maximumTextLength = 10;
    }];
    dialogViewController.shouldEnableSubmitButtonBlock = ^BOOL(__kindof QMUIDialogTextFieldViewController * _Nonnull aDialogViewController) {
        if ([aDialogViewController.textFields.firstObject.text isEqualToString:[AuthSignin_model sharedInstance].data.user_info.nick_name] || aDialogViewController.textFields.firstObject.text.length == 0) {
            return NO;
        }
        return YES;

    };
//    dialogViewController.shouldManageTextFieldsReturnEventAutomatically = YES;// 让键盘的 Return 键也能触发确定按钮的事件。这个属性默认就是 YES，这里为写出来只是为了演示
    [dialogViewController addCancelButtonWithText:@"取消" block:nil];
    [dialogViewController addSubmitButtonWithText:@"确定" block:^(__kindof QMUIDialogTextFieldViewController * _Nonnull aDialogViewController) {
        //        [QMUITips showSucceed:@"提交成功" inView:self.view hideAfterDelay:1.2];
        
                [aDialogViewController hide];
        
                NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                [dict setObject:AuthSignin_model.sharedInstance.data.token forKey:@"token"];
        
        
                [dict setObject:app_code forKey:@"appCode"];
                [dict setObject:aDialogViewController.textFields.firstObject.text forKey:@"nickeName"];
                __block QMUITips *qmui_tip = [QMUITips showLoading:@"请求中..." inView:self.navigationController.view];
        
                [PPHTTPRequest req:@"java/app/user/updateNickeName" parameters:dict success:^(id response) {
                    NSString *error_code = [NSString stringWithFormat:@"%@", response[@"error_code"]];
                    if ([error_code isEqualToString:@"0"]) {
                        AuthSignin_model.sharedInstance.data.user_info.nick_name = aDialogViewController.textFields.firstObject.text ;
                        NSString *dictStr = [AuthSignin_model.sharedInstance mj_JSONString];
                        [[NSUserDefaults standardUserDefaults] setObject:dictStr forKey:@"ank_sign"];
                        [qmui_tip showSucceed:@"修改成功" hideAfterDelay:2];

                        // 更新页面
                        [self setupSections];
                    }
        
                    else
                        //            if ([error_code isEqualToString:@""])
                    {
        
                        [qmui_tip showError:response[@"error_msg"] hideAfterDelay:2];
        
                    }
                } failure:^(NSError *error) {
                    
                    [qmui_tip showError:[error localizedDescription] hideAfterDelay:2];

                }];
        
    }];
    [dialogViewController show];
    return;
    
//    __weak __typeof(self) weakSelf = self;
//
//    MMPopupItemHandler block = ^(NSInteger index){
//        NSLog(@"clickd %@ button",@(index));
//    };
//
    MMPopupCompletionBlock completeBlock = ^(MMPopupView *popupView, BOOL finished){
        NSLog(@"animation complete");
    };
    
    MMAlertView *alertView = [[MMAlertView alloc] initWithInputTitle:@"提示" detail:@"设置名称" placeholder:@"请输入新名称" handler:^(NSString *text) {
        DLog(@"input:%@",text);
        
        
        if ([Anktool strIsBlank:text]) {
            [MBProgressHUD showTipMessageInView:@"请输入姓名"];
            return;
        }
           
        
    }];
    alertView.inputView.text = [AuthSignin_model sharedInstance].data.user_info.nick_name;
    alertView.attachedView = self.view;
    alertView.attachedView.mm_dimBackgroundBlurEnabled = YES;
    alertView.attachedView.mm_dimBackgroundBlurEffectStyle = UIBlurEffectStyleExtraLight;
    [alertView showWithBlock:completeBlock];
    
   
    
    
}
#pragma mark - ================== 相册选图、拍照、预览图片 ==================
- (void)btnSelectPhotoPreview
{
    [self showWithPreview:YES];
}

- (void)btnSelectPhotoLibrary
{
    [self showWithPreview:NO];
}

- (void)showWithPreview:(BOOL)preview
{
    ZLPhotoActionSheet *a = [self getPas];
    
    if (preview) {
        [a showPreviewAnimated:YES];
    } else {
        [a showPhotoLibrary];
    }
}

- (void)showCamera
{
    ZLCustomCamera *camera = [[ZLCustomCamera alloc] init];
    camera.allowRecordVideo = NO;
    @zl_weakify(self);
    camera.doneBlock = ^(UIImage *image, NSURL *videoUrl) {
        @zl_strongify(self);
//        [self saveImage:image videoUrl:videoUrl];
        if (image) {
            [self upload_portrait_and_update:@[image]];
        }
    };
    
    [self showDetailViewController:camera sender:nil];
}


- (ZLPhotoActionSheet *)getPas
{
    ZLPhotoActionSheet *actionSheet = [[ZLPhotoActionSheet alloc] init];
    
#pragma mark - 参数配置 optional，可直接使用 defaultPhotoConfiguration
    
    //以下参数为自定义参数，均可不设置，有默认值
//    actionSheet.configuration.sortAscending = self.sortSegment.selectedSegmentIndex==0;
//    actionSheet.configuration.allowSelectImage = self.selImageSwitch.isOn;
//    actionSheet.configuration.allowSelectGif = self.selGifSwitch.isOn;
//    actionSheet.configuration.allowSelectVideo = self.selVideoSwitch.isOn;
//    actionSheet.configuration.allowSelectLivePhoto = self.selLivePhotoSwitch.isOn;
//    actionSheet.configuration.allowForceTouch = self.allowForceTouchSwitch.isOn;
//    actionSheet.configuration.allowEditImage = self.allowEditSwitch.isOn;
//    actionSheet.configuration.allowEditVideo = self.allowEditVideoSwitch.isOn;
//    actionSheet.configuration.allowSlideSelect = self.allowSlideSelectSwitch.isOn;
//    actionSheet.configuration.allowMixSelect = self.mixSelectSwitch.isOn;
//    actionSheet.configuration.allowDragSelect = self.allowDragSelectSwitch.isOn;
    //设置相册内部显示拍照按钮
//    actionSheet.configuration.allowTakePhotoInLibrary = self.takePhotoInLibrarySwitch.isOn;
//    //设置在内部拍照按钮上实时显示相机俘获画面
//    actionSheet.configuration.showCaptureImageOnTakePhotoBtn = self.showCaptureImageSwitch.isOn;
//    //设置照片最大预览数
//    actionSheet.configuration.maxPreviewCount = self.previewTextField.text.integerValue;
//    //设置照片最大选择数
    actionSheet.configuration.maxSelectCount = 1;
//    actionSheet.configuration.maxVideoSelectCountInMix = 3;
//    actionSheet.configuration.minVideoSelectCountInMix = 1;
    //设置允许选择的视频最大时长
//    actionSheet.configuration.maxVideoDuration = self.maxVideoDurationTextField.text.integerValue;
//    //设置照片cell弧度
//    actionSheet.configuration.cellCornerRadio = self.cornerRadioTextField.text.floatValue;
    //单选模式是否显示选择按钮
    //    actionSheet.configuration.showSelectBtn = YES;
    //是否在选择图片后直接进入编辑界面
//    actionSheet.configuration.editAfterSelectThumbnailImage = self.editAfterSelectImageSwitch.isOn;
    //是否保存编辑后的图片
    //    actionSheet.configuration.saveNewImageAfterEdit = NO;
    //设置编辑比例
    //    actionSheet.configuration.clipRatios = @[GetClipRatio(7, 1)];
    //是否在已选择照片上显示遮罩层
//    actionSheet.configuration.showSelectedMask = self.maskSwitch.isOn;
    //    actionSheet.configuration.showSelectedIndex = NO;
    //颜色，状态栏样式
    //    actionSheet.configuration.previewTextColor = [UIColor brownColor];
    //    actionSheet.configuration.selectedMaskColor = [UIColor purpleColor];
    //    actionSheet.configuration.navBarColor = [UIColor orangeColor];
    //    actionSheet.configuration.navTitleColor = [UIColor blackColor];
    //    actionSheet.configuration.bottomBtnsNormalTitleColor = kRGB(80, 160, 100);
    //    actionSheet.configuration.bottomBtnsDisableBgColor = kRGB(190, 30, 90);
    //    actionSheet.configuration.bottomViewBgColor = [UIColor blackColor];
    //    actionSheet.configuration.statusBarStyle = UIStatusBarStyleDefault;
    //是否允许框架解析图片
//    actionSheet.configuration.shouldAnialysisAsset = self.allowAnialysisAssetSwitch.isOn;
    //框架语言
//    actionSheet.configuration.languageType = self.languageSegment.selectedSegmentIndex;
    //自定义多语言
    //    actionSheet.configuration.customLanguageKeyValue = @{@"ZLPhotoBrowserCameraText": @"没错，我就是一个相机"};
    //自定义图片
    //    actionSheet.configuration.customImageNames = @[@"zl_navBack"];
    
    //是否使用系统相机
    //    actionSheet.configuration.useSystemCamera = YES;
    //    actionSheet.configuration.sessionPreset = ZLCaptureSessionPreset1920x1080;
    //    actionSheet.configuration.exportVideoType = ZLExportVideoTypeMp4;
    //    actionSheet.configuration.allowRecordVideo = NO;
    //    actionSheet.configuration.maxRecordDuration = 5;
#pragma mark - required
    //如果调用的方法没有传sender，则该属性必须提前赋值
    actionSheet.sender = self;
    //记录上次选择的图片
    actionSheet.arrSelectedAssets =  self.lastSelectAssets;
    
    @zl_weakify(self);
    [actionSheet setSelectImageBlock:^(NSArray<UIImage *> * _Nonnull images, NSArray<PHAsset *> * _Nonnull assets, BOOL isOriginal) {
        @zl_strongify(self);
        self.arrDataSources = images;
        self.isOriginal = isOriginal;
        self.lastSelectAssets = assets.mutableCopy;
        self.lastSelectPhotos = images.mutableCopy;
        
        NSLog(@"image:%@", images);
        //解析图片
        [self anialysisAssets:assets original:isOriginal];

    }];
    
    actionSheet.selectImageRequestErrorBlock = ^(NSArray<PHAsset *> * _Nonnull errorAssets, NSArray<NSNumber *> * _Nonnull errorIndex) {
        NSLog(@"图片解析出错的索引为: %@, 对应assets为: %@", errorIndex, errorAssets);
    };
    
    actionSheet.cancleBlock = ^{
        NSLog(@"取消选择图片");
    };
    
    return actionSheet;
}

- (void)anialysisAssets:(NSArray<PHAsset *> *)assets original:(BOOL)original
{
    ZLProgressHUD *hud = [[ZLProgressHUD alloc] init];
    //该hud自动15s消失，请使用自己项目中的hud控件
    [hud show];
    
    
    @zl_weakify(self);
    [ZLPhotoManager anialysisAssets:assets original:original completion:^(NSArray<UIImage *> *images) {
        @zl_strongify(self);
        [hud hide];
        self.arrDataSources = images;
        self.lastSelectPhotos = images.mutableCopy;
        
        NSLog(@"%@", images);
        [self upload_portrait_and_update:images];
        
    }];
}
- (void)upload_portrait_and_update:(NSArray *)images{
    NSString *img_name = [AuthSignin_model.sharedInstance.data.user_info.mobile stringByAppendingString:@(NSDate.date.timeIntervalSince1970).stringValue]
    ;
    NSString *url_str = @"api/Upload/image";
    NSDictionary *params = @{@"Authorization" : AuthSignin_model.sharedInstance.data.token};
    __block QMUITips *tip_ui = [QMUITips showLoading:@"图片上传..." inView:self.navigationController.view];
    [PPNetworkHelper uploadImagesWithURL:url_str parameters:params name:@"file" images:images fileNames:@[img_name] imageScale:0.5 imageType:nil progress:^(NSProgress *progress) {
        
    } success:^(id responseObject) {
        DLog(@"url:%@ params:%@ res:%@", url_str, params, responseObject);
        NSDictionary *response = responseObject;
        NSString *error_code = [NSString stringWithFormat:@"%@", response[@"error_code"]];
        if ([error_code isEqualToString:@"0"]) {
            NSDictionary *data_dic = response[@"data"];
            NSString *uploaded_url = [NSString stringWithFormat:@"%@", [data_dic objectForKey:@"url"]];
            if (uploaded_url.length > 0 ) {
                
                
                
                NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                [dict setObject:app_code forKey:@"appCode"];
                [dict setObject:AuthSignin_model.sharedInstance.data.token forKey:@"token"];
                [dict setObject:uploaded_url forKey:@"iconUrl"];
                
                
                [tip_ui showLoading:@"上传成功，更新中..."];
                [PPHTTPRequest req:@"java/app/user/updateIcon" parameters:dict success:^(id response) {
                    NSString *error_code = [NSString stringWithFormat:@"%@", response[@"error_code"]];
                    if ([error_code isEqualToString:@"0"]) {
                        
                        [AuthSignin_model sharedInstance].data.user_info.avatar_url = uploaded_url;
                        NSString *dictStr = [AuthSignin_model.sharedInstance mj_JSONString];
                        [[NSUserDefaults standardUserDefaults] setObject:dictStr forKey:@"ank_sign"];
                        [tip_ui showSucceed:@"更换成功" hideAfterDelay:2];
                        [self setupSections];
                    }
                    else{
                        
                        
                        [tip_ui showError:response[@"error_msg"] hideAfterDelay:2];
                        
                        
                    }
                    
                } failure:^(NSError *error) {
                    [tip_ui showError:error.localizedDescription hideAfterDelay:2];
                    
                    
                }];
                
                
                
                
            }
        }
        
        else
            //            if ([error_code isEqualToString:@""])
        {
            
            [tip_ui showError:response[@"error_msg"] hideAfterDelay:2];
            
        }
    } failure:^(NSError *error) {
        [tip_ui showError:error.localizedDescription hideAfterDelay:2];
    }];
    
}
- (void)saveImage:(UIImage *)image videoUrl:(NSURL *)videoUrl
{
    ZLProgressHUD *hud = [[ZLProgressHUD alloc] init];
    [hud show];
    @zl_weakify(self);
    if (image) {
        [ZLPhotoManager saveImageToAblum:image completion:^(BOOL suc, PHAsset *asset) {
            @zl_strongify(self);
            if (suc) {
                self.arrDataSources = @[image];
                self.lastSelectPhotos = @[image].mutableCopy;
                self.lastSelectAssets = @[asset].mutableCopy;
                
            } else {
                ZLLoggerDebug(@"图片保存失败");
            }
            [hud hide];
        }];
    } else if (videoUrl) {
        [ZLPhotoManager saveVideoToAblum:videoUrl completion:^(BOOL suc, PHAsset *asset) {
            @zl_strongify(self);
            if (suc) {
                [ZLPhotoManager requestImageForAsset:asset size:CGSizeMake(300, 300) progressHandler:nil completion:^(UIImage *image, NSDictionary *info) {
                    @zl_strongify(self);
                    if ([[info objectForKey:PHImageResultIsDegradedKey] boolValue]) {
                        return;
                    }
                    self.arrDataSources = @[image];
                    self.lastSelectPhotos = @[image].mutableCopy;
                    self.lastSelectAssets = @[asset].mutableCopy;
                    
                    [hud hide];
                }];
            } else {
                ZLLoggerDebug(@"视频保存失败");
                [hud hide];
            }
        }];
    }
}
@end
